<!DOCTYPE html>
<html lang="zh-cmn-Hans" prefix="og: http://ogp.me/ns#" class="han-init">
<head>
  <meta charset="utf-8">
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <link rel="icon" href="http://upeng.github.io/favicon.ico">
  <title>upeng</title>
  <link rel="stylesheet" href="/css/style.css">
  <link rel="stylesheet" href="/lib/fancybox/jquery.fancybox-1.3.4.css">
  <!--在这里倒入jquery 方便处理部分页面的jquery-->
  <script src="https://cdn.staticfile.org/jquery/1.7/jquery.min.js" type="text/javascript" ></script>
</head>

<body>
	<header class="site-header navfixed-false">
  <div class="container">
      <h1><a href="/" title="upeng"><span class="octicon octicon-mark-github"></span> upeng</a></h1>
      <nav class="site-header-nav" role="navigation">
        
              
              <a href="/"  class=" site-header-nav-item hvr-underline-from-center" title="Home">Home</a>
        
              
              <a href="/categories/"  class=" site-header-nav-item hvr-underline-from-center" title="Categories">Categories</a>
        
              
              <a href="/bookmark/"  class=" site-header-nav-item hvr-underline-from-center" title="Bookmark">Bookmark</a>
        
              
              <a href="http://shareup.sinaapp.com"  class=" site-header-nav-item hvr-underline-from-center" title="Share">Share</a>
        
              
              <a href="/about/"  class=" site-header-nav-item hvr-underline-from-center" title="About">About</a>
        
      </nav>
  </div>
</header>

	
<section class="collection-head geopattern" data-pattern-id="从编写到发布laravel扩展" >
    <div class="container">
        <div class="collection-title">
            <h1 class="collection-header">
                从编写到发布laravel扩展
            </h1>
            
                <div class="collection-info">
                    <span class="meta-info">
                        <span class="octicon octicon-calendar"></span>
                        <time datetime="2016-10-11T02:40:23.000Z" itemprop="datePublished">2016-10-11</time>
                    </span>
                    
                        <span class="meta-info">
                            <span class="octicon octicon-file-directory"></span>
                            <a href='/categories/PHP/' title=''>PHP</a>
                        </span>
                    
                </div>
            
        </div>
    </div>
</section>
	<section class="container">
    <div class="columns">
        <!-- -->
        <div class="column three-fourths">
            <article class="article-content markdown-body">
                <h3 id="工具准备"><a href="#工具准备" class="headerlink" title="工具准备"></a>工具准备</h3><blockquote>
<p>创建开源项目三工具github、packageist、composer</p>
</blockquote>
<pre><code> github: git仓库，是用于存放源代码的地方
 packagist: 用于发布github上的扩展程序或者项目
 composer: 用于使用代码的工具
</code></pre><a id="more"></a>
<p><code>github-&gt;packagist-&gt;composer</code></p>
<ol>
<li>怎样写一个laravel扩展，发布到packagist，提供composer方法</li>
<li>git命令熟悉</li>
</ol>
<h3 id="写laravel扩展"><a href="#写laravel扩展" class="headerlink" title="写laravel扩展"></a>写laravel扩展</h3><h4 id="本地编写"><a href="#本地编写" class="headerlink" title="本地编写"></a>本地编写</h4><p>本地编写package，完成后，在laravel根目录下的composer.json中添加一行<br><code>&quot;Upstriving\\Curd\\&quot;: &quot;package/upstriving/curd/src&quot;</code></p>
<pre><code> &quot;autoload&quot;: {
        &quot;classmap&quot;: [
            &quot;database&quot;
        ],
        &quot;psr-4&quot;: {
            &quot;App\\&quot;: &quot;app/&quot;,
            &quot;Upstriving\\Curd\\&quot;: &quot;package/upstriving/curd/src&quot;
        }
    },
</code></pre><p>添加之后<code>composer dump-autoload</code>将之加到路由中<br><code>php artisan tinker</code>测试</p>
<pre><code>&gt;&gt;&gt; app(&#39;sqladmin&#39;)
=&gt; Upstriving\Curd\SQLAdmin {#629}
&gt;&gt;&gt; app(&#39;sqladmin&#39;)-&gt;makeSelect(&#39;user&#39;,&#39;id,name&#39;,[&#39;id&#39;=&gt;2]);
=&gt; [
     &quot;sql&quot; =&gt; &quot;select id,name from user where id=?&quot;,
     &quot;data&quot; =&gt; [
       2,
     ],
   ]
&gt;&gt;&gt; app(&#39;sqladmin&#39;)-&gt;makeDelete(&#39;user&#39;,[&#39;name&#39;=&gt;&#39;upfriend&#39;])
=&gt; [
     &quot;sql&quot; =&gt; &quot;delete from user where `name`=?&quot;,
     &quot;data&quot; =&gt; [
       &quot;upfriend&quot;,
     ],
   ]
</code></pre><h4 id="生成composer-json"><a href="#生成composer-json" class="headerlink" title="生成composer.json"></a>生成composer.json</h4><pre><code>composer init
This command will guide you through creating your composer.json config.

Package name (&lt;vendor&gt;/&lt;name&gt;) [yupeng6/curd]: upstriving/curd
Description []: assemble sql statements quickly
Author [upeng &lt;825415473@qq.com&gt;, n to skip]:
Minimum Stability []: dev
Package Type (e.g. library, project, metapackage, composer-plugin) []:
License []: MIT

Define your dependencies.

Would you like to define your dependencies (require) interactively [yes]? no
Would you like to define your dev dependencies (require-dev) interactively [yes]? no

{
    &quot;name&quot;: &quot;upstriving/curd&quot;,
    &quot;description&quot;: &quot;assemble sql statements quickly&quot;,
    &quot;license&quot;: &quot;MIT&quot;,
    &quot;authors&quot;: [
        {
            &quot;name&quot;: &quot;upeng&quot;,
            &quot;email&quot;: &quot;825415473@qq.com&quot;
        }
    ],
    &quot;minimum-stability&quot;: &quot;dev&quot;,
    &quot;require&quot;: {}
}

Do you confirm generation [yes]? yes
</code></pre><h4 id="生成composer-json-1"><a href="#生成composer-json-1" class="headerlink" title="生成composer.json"></a>生成composer.json</h4><blockquote>
<p>添加autoload</p>
<pre><code>&quot;autoload&quot;: {
    &quot;psr-4&quot;: {
         &quot;Upstriving\\Curd\\&quot;: &quot;src/&quot;
    }
}
</code></pre></blockquote>
<h4 id="推送到github"><a href="#推送到github" class="headerlink" title="推送到github"></a>推送到github</h4><blockquote>
<p>当前扩展目录下执行</p>
</blockquote>
<pre><code>git init
git add .
git commit -m &#39;add new package&#39;
</code></pre><p>github手动创建一个<code>repository(laravel-sqladmin)</code><br>在本地目录下，复制两行命令并执行，将本地代码推送到github</p>
<pre><code>git remote add origin git@github.com:upeng/laravel-sqladmin.git
git push -u origin master
</code></pre><p>新增readme.md</p>
<h4 id="通过github的package服务发布到packagist中"><a href="#通过github的package服务发布到packagist中" class="headerlink" title="通过github的package服务发布到packagist中"></a>通过github的package服务发布到packagist中</h4><p>供其他开发者通过composer使用<br>登录<code>https://packagist.org/</code>,<br><img src="http://ww2.sinaimg.cn/mw1024/006iFiRLjw1f8o4ehp6l9j31c30kejve.jpg" alt="此处输入图片的描述"><br>拿到token值，回到<code>github/larvavel-sqladmin/settings/integrations &amp; service</code><br>执行<code>add service/packagist</code><br><img src="http://ww2.sinaimg.cn/mw1024/006iFiRLjw1f8o4eibz58j31j50u9gsy.jpg" alt="此处输入图片的描述"><br>输入用户名user和token(从packagist中获取)<br>成功之后如下<br><img src="http://ww3.sinaimg.cn/mw1024/006iFiRLjw1f8o4eizjdvj31k70ra7bl.jpg" alt="此处输入图片的描述"></p>
<p>再次回到packagist中，submit刚才那个repository地址<br><img src="http://ww3.sinaimg.cn/mw1024/006iFiRLjw1f8o4ejjp7zj30wk0d8jsx.jpg" alt="此处输入图片的描述"><br><img src="http://ww2.sinaimg.cn/mw1024/006iFiRLjw1f8o4ek6aagj30wp0epmzr.jpg" alt="此处输入图片的描述"><br><img src="http://ww1.sinaimg.cn/mw1024/006iFiRLjw1f8o4ektd7qj318o0hg77p.jpg" alt="此处输入图片的描述"></p>
<p>提示这个package is not auto_updated，需要到github中设置一下<br>github/larvavel-sqladmin/settings/integrations &amp; service/packagist<br>点击test service，<br><img src="http://ww3.sinaimg.cn/mw1024/006iFiRLjw1f8o4elc6eej31600q6wiv.jpg" alt="此处输入图片的描述"></p>
<p>如果显示<br><code>Okay, the test payload is on its way.</code><br>说明自动更新没有问题，再次回到packagist发现刚刚的提示已经不见了<br><img src="http://ww3.sinaimg.cn/mw1024/006iFiRLjw1f8o4em26svj30n10d5myx.jpg" alt="此处输入图片的描述"></p>
<h4 id="修改或新增文件，观察是否实时更新到packagist"><a href="#修改或新增文件，观察是否实时更新到packagist" class="headerlink" title="修改或新增文件，观察是否实时更新到packagist"></a>修改或新增文件，观察是否实时更新到packagist</h4><blockquote>
<p>新增readme.file</p>
<pre><code>git add .
git commit -m &#39;&#39;
git push
</code></pre><p>增加版本号</p>
</blockquote>
<p><code>git tag 1.0 -a</code><br>输入: release version 1.0<br><code>git push --tags</code><br>发现github上多了一个版本号,packagist版本也随之更新<br><img src="http://ww3.sinaimg.cn/mw1024/006iFiRLjw1f8o4emqsblj312x0nv446.jpg" alt="此处输入图片的描述"></p>

            </article>
            
                <div class="share">
                    <!--开启分享-->
<div class="share-component" data-disabled="google,twitter,facebook" data-description="工具准备
创建开源项目三工具github、packag..."></div>

<script src="/js/share.min.js"></script>

                </div>    
            
            
                
<div class="comments">
	<div class="ds-thread" data-thread-key="publish-laravel-package" data-title="从编写到发布laravel扩展" data-url="http://upeng.github.io/2016/10/11/publish-laravel-package/"></div>
	<script type="text/javascript">
	var duoshuoQuery = {short_name:"upeng"};
		(function() {
			var ds = document.createElement('script');
			ds.type = 'text/javascript';ds.async = true;
			ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
			ds.charset = 'UTF-8';
			(document.getElementsByTagName('head')[0]
			 || document.getElementsByTagName('body')[0]).appendChild(ds);
		})();
	</script>
</div>

            
        </div>
        <div class="column one-fourth">
            
                
                


<h3>Post Directory</h3>

<div id="post-directory-module">
	<section class="post-directory">
		<p><strong class="toc-title">文章目录</strong></p>
		<ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#工具准备"><span class="toc-text">工具准备</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#写laravel扩展"><span class="toc-text">写laravel扩展</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#本地编写"><span class="toc-text">本地编写</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#生成composer-json"><span class="toc-text">生成composer.json</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#生成composer-json-1"><span class="toc-text">生成composer.json</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#推送到github"><span class="toc-text">推送到github</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#通过github的package服务发布到packagist中"><span class="toc-text">通过github的package服务发布到packagist中</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#修改或新增文件，观察是否实时更新到packagist"><span class="toc-text">修改或新增文件，观察是否实时更新到packagist</span></a></li></ol></li></ol>
	</section>
</div>
            
        </div>
    </div>
</section>

<footer class="container">
    <div class="site-footer" role="contentinfo">
        <div class="copyright left mobile-block">
                © 2016
                <span title="yupeng">yupeng</span>
                <a href="javascript:window.scrollTo(0,0)" class="right mobile-visible">TOP</a>
        </div>

        <ul class="site-footer-links right mobile-hidden">
            <li>
                <a href="javascript:window.scrollTo(0,0)" >TOP</a>
            </li>
        </ul>

        <a href="https://github.com/upeng" target="_blank" aria-label="view source code">
            <span class="mega-octicon octicon-mark-github" title="GitHub"></span>
        </a>

        <ul class="site-footer-links mobile-hidden">
            
                  
                  <li>
                    <a href="/"  title="Home">Home</a>
                  </li>
            
                  
                  <li>
                    <a href="/categories/"  title="Categories">Categories</a>
                  </li>
            
                  
                  <li>
                    <a href="/bookmark/"  title="Bookmark">Bookmark</a>
                  </li>
            
                  
                  <li>
                    <a href="http://shareup.sinaapp.com"  title="Share">Share</a>
                  </li>
            
                  
                  <li>
                    <a href="/about/"  title="About">About</a>
                  </li>
            
            <li>
                <a href="/atom.xml">
                    <span class="octicon octicon-rss" style="color:orange;"></span>
                </a>
            </li>
        </ul>
    </div>
</footer>


		<script src="/js/geopattern.js"></script>

		
			<script src="/js/toc.js"></script>
		

		<script src="/js/highlight.pack.js"></script>
		<script src="/lib/fancybox/jquery.fancybox-1.3.4.pack.js"></script>

		<script src="/js/index.js"></script>

		 <script src="/js/popular_repo.js"></script> 

	</body>
</html>